package com.example.demo1.pojo.result;

public class result<T> {
    private boolean success;
    private String message;
    private T data;
    private Integer code;

    public result() {}

    public result(boolean success, String message, T data, Integer code) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.code = code;
    }

    public static <T> result<T> success(T data) {
        return new result<>(true, "操作成功", data, 200);
    }

    public static <T> result<T> success(String message, T data) {
        return new result<>(true, message, data, 200);
    }

    public static <T> result<T> error(String message) {
        return new result<>(false, message, null, 400);
    }

    public static <T> result<T> error(String message, Integer code) {
        return new result<>(false, message, null, code);
    }

    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
